public class MortageCalculator {
    private final static byte PERCENT = 100;
    private  final static byte MONTHS_IN_YEAR = 12;

    private float principal;
    private float annualInterst;
    byte years;
    
    public int getNumberOfPayments() {
        return years*MONTHS_IN_YEAR;
    }

    public MortageCalculator(float principal, float annualInterst, byte years) {
        this.principal = principal;
        this.annualInterst = annualInterst;
        this.years = years;
    }

    public double calculateMortgage() {
        double monthlyInterest = annualInterst / PERCENT / MONTHS_IN_YEAR;
        float numberOfPayments = years * MONTHS_IN_YEAR;
    
        double tmp = Math.pow(1 + monthlyInterest, numberOfPayments);
        double mortgage = principal * monthlyInterest *
                tmp / (tmp - 1);
        return mortgage;
    }

    public double calculateBalance(short numberOfPaymentsMade) {
        double monthlyInterest = annualInterst /PERCENT / MONTHS_IN_YEAR;
        float numberOfPayments = years * MONTHS_IN_YEAR;
    
        double balance = principal
                * (Math.pow(1 + monthlyInterest, numberOfPayments)
                        - Math.pow(1 + monthlyInterest, numberOfPaymentsMade))
                / (Math.pow(1 + monthlyInterest, numberOfPayments) - 1);
        return balance;
    }
    
}
